/* 
    1. 配置公共的url
    2. 对请求和返回进行拦截
    3. 加遮罩
    https://mobile.ant.design/components/toast-cn/
*/
import axios from 'axios';
import {Toast} from 'antd-mobile'
import Loading from '../assets/images/loading.jpg'

const instance = axios.create({
    baseURL:process.env.REACT_APP_BASEURL,
});
// 请求的拦截器
instance.interceptors.request.use(
    function(config){
       // console.log(config);
       Toast.show(<img style={{width:'100px',height:'100px'}} src={Loading}></img>)
        return config
    },
    function(error){
        Toast.hide()
    return Promise.reject(error)
})

// 响应的拦截器
instance.interceptors.response.use(
    function(response){
        Toast.hide()
        return response.data
    },
    (error)=>{
        Toast.hide()
    return Promise.reject(error)
    }
)
export default instance